<template>
  <div>
    <!-- 头部 -->
    <p-head @getcontent="getcontents"></p-head>
    <!-- 横通 -->
    <!--    <div class="searchboeder">-->
    <!--      <input type="text" /> <span class="iconfont yf-icon-sousuo1"></span>-->
    <!--    </div>-->

    <!-- 搜索出的内容 -->
    <div class="layout">
      <ul class="searchCASE">
        <li v-for="item in newlist" :key="item.id">
          <div class="search_content1">
            <div class="search_right1">
              <img :src="item.thumb" alt="" />
            </div>
            <div class="search_left1">
              <p>{{ item.create_time }}</p>
              <h3>
                {{ item.title }}
              </h3>

              <div class="search" @click="toNewdetail(item.id)">了解详情</div>
            </div>
          </div>
        </li>
      </ul>
    </div>

    <div class="layout">
      <template v-if="newlist.length == 0">
        <el-empty description="暂无数据"></el-empty>
      </template>
    </div>

    <!-- 新闻推荐 -->
    <h2 class="caseRecommend">案例推荐</h2>

    <div class="casebanner">
      <el-carousel indicator-position="outside">
        <el-carousel-item
          v-for="k in Math.ceil(isrecomnews.length / 2)"
          :key="k"
        >
          <ul class="CASE">
            <li
              v-for="item in isrecomnews.slice((k - 1) * 2, k * 2)"
              :key="item.id"
            >
              <div class="snew_content1">
                <div class="snew_right1">
                  <img :src="item.thumb" alt="" />
                </div>
                <div class="snew_left1">
                  <p>{{ item.create_time }}</p>
                  <h3>
                    {{ item.title }}
                  </h3>

                  <div class="know1" @click="toNewdetail(item.id)">
                    了解详情
                  </div>
                </div>
              </div>
            </li>
          </ul>
        </el-carousel-item>
      </el-carousel>
    </div>
    <!-- 底部 -->
    <p-foot></p-foot>
  </div>
</template>
<script>
import PHead from "../../components/pHead.vue";
import { get } from "@/http/request";
export default {
  components: { PHead },
  props: [],
  data() {
    return {
      newactiveName: "newall",
      banner: [],
      newlist: [],
      new_nav: [],
      new_one: [],
      total: "",
      page: 1,
      allpage: "",
      limit: 7,
      isrecomnews: [],
    };
  },
  methods: {
    getCodeResult(category, searchContent) {
      this.$axios
        .post("后端接口地址", {
          category: category,
          searchContent: searchContent,
        })
        .then((res) => {
          this.newsContent = res.data.content;
        });
    },
    handleclikNews(tab, event) {
      this.page = 1;
      /**判断是否有值请求数据**/
      this.newlist = [];
      let smcate_id = tab.$attrs.newsid;
      console.log(smcate_id);
      get("/api/home/getall", {
        page: this.page,
        limit: this.limit,
        news_id: smcate_id,
      })
        .then((res) => {
          console.log(res);
          this.newlist = res.data.news.list;
          this.new_nav = res.data.news.new_nav;
          this.new_one = this.newlist[0];
          this.total = res.data.news.total;
          this.allpage = Math.ceil(this.total / this.limit);
          // console.log(this.newlist);
        })
        .catch((err) => {
          console.log(err);
        });
    },

    // 带参数
    toNewdetail(newid) {
      this.$router.push({ path: "/newdetail", query: { newid: newid } });
    },
    domore(val) {
      let smcate_id = val;
      //查看当前有几页
      let pa = Math.ceil(this.total / this.limit);
      if (this.page >= pa) {
        this.page = pa;
      } else {
        this.page++;
      }
      if (this.page <= pa) {
        get("/api/home/getall", {
          page: this.page,
          limit: this.limit,
          news_id: smcate_id,
        })
          .then((res) => {
            let newlist = res.data.news.list;
            this.new_one = newlist[0];
            this.new_nav = res.data.news.new_nav;
            newlist.forEach((item, index) => {
              this.newlist.push(item);
            });
          })
          .catch((err) => {
            console.log(err);
          });
      }
    },

    /*
     * 搜索获取数据
     * **/
    getDataList(kword) {
      get("/api/home/getall", { page: 1, limit: 10, kword: kword })
        .then((res) => {
          console.log(res.data);
          if (res.data.code == 200) {
            this.newlist = res.data.news.list;
            this.isrecomnews = res.data.news.isrecomnews;
            this.total = res.data.news.total;
            this.allpage = Math.ceil(this.total / this.limit);
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },

    getcontents(countent) {
      this.getDataList(countent);
    },
  },
  mounted() {
    let keyword = this.$route.query.qkeyword;
    this.getDataList(keyword);
  },
  computed: {},
  watch: {},
  activated() {
    let category = this.$route.query.category;
    let searchContent = this.$route.query.searchContent;
    if (category && keyword) {
      this.getCodeResult(category, searchContent);
    }
  },
};
</script>
<style scoped lang="less">
@import "../../less/index.less";
@import "../../assets/css/reset.css";
.searchboeder {
  width: 60%;
  height: 50px;
  margin: 30px auto;
  position: relative;
}
.searchboeder input {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 50px;
  border: none;
  border: 1px solid #999;
  outline: none;
  font: 16px/50px "微软雅黑";
  text-indent: 2rem;
}
.searchboeder:hover {
  input {
    border: 1px solid #426efe;
    top: -5px;
    transition: 0.5s;
    box-shadow: 0px 2px 10px 0px #426efe;
  }
  span {
    top: 15%;
    transition: 0.5s;
    color: #426efe;
  }
}
.searchboeder span {
  position: absolute;
  right: 3%;
  top: 20%;
  font-size: 30px;
  color: #999;
}

.casebanner {
  height: 400px;
  width: 80%;
  margin: 0 auto;
}
/deep/.casebanner .el-carousel {
  height: 100%;
  width: 100%;
  .el-carousel__container {
    height: 90%;
    width: 100%;
    overflow: hidden;
  }
}
/deep/.el-carousel__item {
  height: 100%;
  background-color: #fff;
}
.CASE {
  height: 99%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-sizing: border-box;
  overflow: hidden;
  // background-color: pink;
  .case_card {
    width: 45%;
    border: 1px solid #f5f5f5;
  }
}

.casebanner ul li {
  /* background-color: pink; */
  height: 60%;
  width: 45%;
  margin-bottom: 20px;
  box-sizing: border-box;
}

.snew_content1 {
  height: 100%;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.snew_right1 {
  height: 100%;
  width: 45%;
}

.snew_right1 img {
  height: 100%;
  width: 100%;
}

.snew_left1 {
  width: 55%;
  padding-left: 18px;
}

.snew_left1 p {
  font: 14px;
  color: #333333;
  margin-top: 20px;
  margin-bottom: 26px;
}

.snew_left1 h3 {
  font: 20px "微软雅黑";
  margin-bottom: 30px;
  overflow: hidden;
  height: 30px;
  width: 100%;
}

.snew_left1 .know1 {
  width: 92px;
  height: 30px;
  /* background-color: @primary; */
  font: 14px/30px "微软雅黑";
  color: #666666;
  text-align: center;
  border: 1px solid #e4e4e4;
}

.snew_left1 .know1:hover {
  background-color: #3a6cfe;
  color: #fff;
  cursor: pointer;
}

.toNews1:hover {
  background-color: #3a6cfe;
  color: #fff;
  cursor: pointer;
}

/deep/.el-carousel__indicators--horizontal {
  position: absolute;
  left: auto;
  right: 45%;
  bottom: 10px;
  text-align: right;

  .el-carousel__indicator--horizontal button {
    width: 12px;
    height: 12px;
    background: #ffffff;
    border-radius: 50%;
    border: 2px solid #f1f1f1;
    opacity: 0.8;
  }

  .el-carousel__indicator--horizontal.is-active button {
    width: 24px;
    height: 12px;
    background: #426efe;
    opacity: 0.8;
    border: 2px solid #426efe;
    // background-color: #426efe;
    border-radius: 10px;
  }
}
.caseRecommend {
  width: 80%;
  font-size: 16px;
  color: #777777;
  font-weight: normal;
  margin: 20px auto;
}

.searchCASE {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.searchCASE li {
  /* background-color: pink; */
  height: 23%;
  width: 45%;
  margin-bottom: 20px;
  box-sizing: border-box;
}

.search_content1 {
  height: 100%;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.search_right1 {
  height: 100%;
  width: 45%;
}

.search_right1 img {
  height: 100%;
  width: 100%;
}

.search_left1 {
  width: 55%;
  padding-left: 18px;
}

.search_left1 p {
  font: 14px;
  color: #333333;
  margin-top: 20px;
  margin-bottom: 26px;
}

.search_left1 h3 {
  font: 20px "微软雅黑";
  margin-bottom: 30px;
  overflow: hidden;
  height: 30px;
  width: 100%;
}

.search_left1 .know1 {
  width: 92px;
  height: 30px;
  /* background-color: @primary; */
  font: 14px/30px "微软雅黑";
  color: #666666;
  text-align: center;
  border: 1px solid #e4e4e4;
}

.search_left1 .know1:hover {
  background-color: #3a6cfe;
  color: #fff;
  cursor: pointer;
}

.toNews1:hover {
  background-color: #3a6cfe;
  color: #fff;
  cursor: pointer;
}

/* 响应式布局 */

@media screen and (min-width: 992px) {
}

@media screen and (max-width: 992px) {
}

@media screen and (max-width: 768px) {
  .caseRecommend {
    display: none;
  }
  .casebanner {
    display: none;
  }
  .searchCASE li {
    width: 100%;
  }
  .toNews1 {
    margin-top: 60px;
  }
}
@media screen and (max-width: 500px) {
  .caseRecommend {
    display: none;
  }
  .casebanner {
    display: none;
  }
  .toNews1 {
    margin-top: 20px;
  }
}
</style>